package com.shop.record.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.shop.record.pojo.RecordInfo;
import com.shop.record.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @PackgeName: com.shop.record.controller
 * @ClassName: t_storage_recordController
 * @Author: 比巴卜
 * Date: 2021/7/23 10:04
 * project name: shop
 * @Version: 1.8
 * @Description:
 */
@Controller
public class RecordController {
    @Autowired
    private RecordService service;

    //分页查询
        @RequestMapping("/t_Selete")
    public String getSeletePage(Model model, String goodsName, String goodsDesc, String goodsUnit, Integer deptno, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        PageInfo<RecordInfo> page = service.FySelect(deptno, pageNum);
        model.addAttribute("FyList", page);
        model.addAttribute("goodsName", goodsName);
        model.addAttribute("goodsDesc", goodsDesc);
        model.addAttribute("goodsUnit", goodsUnit);
        model.addAttribute("deptno", deptno);
        return "billlist";
    }

    //添加
    @RequestMapping("/t_insert")
    public String toAddPaper() {
        return "billadd";
    }

    @PostMapping("/insert")
    public String addPaper(Model model, RecordInfo record, String tname, Integer deptno, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        service.Insert(record);
        model.addAttribute("FyList", service.FySelect(deptno, pageNum));
        return "billlist";
    }

    //修改
    @RequestMapping("/t_update")
    public String toUpdate(Model model, RecordInfo record) {
        model.addAttribute("bill", record);
        return "billmodify";
    }

    @RequestMapping("/update")
    public String updatess(Model model, RecordInfo record, String tname, Integer deptno, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        System.out.println("gegsgsgsegsgeg");
        service.Update(record);
        model.addAttribute("FyList", service.FySelect(deptno, pageNum));
        return "head";
    }

    //删除
    @RequestMapping("/t_dels")
    //josn注解
    @ResponseBody
    public String deletess(Model model, Integer ids) {
        boolean delete = service.Delete(ids);
        return JSON.toJSONString(delete);
    }
}
